package week.May182025;

/**
 * 题目：100668. 数位和等于下标的最小下标
 * 链接：https://leetcode.cn/contest/weekly-contest-450/problems/smallest-index-with-digit-sum-equal-to-index/
 */
public class SmallestIndex {
    public static void main(String[] args) {
        int[] arr = {1, 10, 11};
        System.out.println(smallestIndex(arr));
    }
    public static int smallestIndex(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int everyNum = nums[i];
            int everySum = 0;
            String numStr = String.valueOf(everyNum);
            for (int j = 0; j < numStr.length(); j++) {
                everySum += Integer.parseInt(String.valueOf(numStr.charAt(j)));
            }
            if (i == everySum) {
                return i;
            }
        }
        return -1;
    }
}
